<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #cvs {
            border: 1px solid #f00;
        }
    </style>
</head>

<body>
    <canvas id="cvs" width="600" height="400"></canvas>
</body>
<script>
    // 1.获取canvas的元素 
    const cvsDom = document.querySelector('#cvs')

    // 2.生成canvas绘制元素 
    const context = cvsDom.getContext('2d');

    context.lineWidth = 10;    // 宽

    context.strokeStyle = 'blue';  // 颜色


    // 3.线段的起始
    context.moveTo(20, 50)

    // 4.线段的终点
    context.lineTo(380, 50);

    context.lineTo(380, 150);

    context.lineTo(20, 150);

    context.lineTo(20, 50);


    // 5.绘制出这条线
    context.stroke();






</script>

</html>